package cn.seocoo.platform.api.util;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.List;

/**
 * 分页
 * @author zhihl
 * @date 2019/04/09
 */
@Data
public class PageBean<T> {
    private Integer pageNum;//当前页
    private Integer pageSize;//页大小
    private Integer count;//总条数
    private Integer totalPage;//总页数
    private List<T> list;//分页结果


    //构造函数
    public PageBean(){}

    public PageBean(Integer pageNum, Integer pageSize, Integer count, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.count = count;
        this.totalPage = (this.count + this.pageSize - 1) / this.pageSize;
        this.list = list;
    }

    public PageBean(List<T> list) {
        if (list instanceof Page) {
            Page<T> page = (Page<T>) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.count = Integer.valueOf(String.valueOf(page.getTotal()));
            this.totalPage = page.getPages();
            this.list = page;

        }
    }

}
